package com.biostime.qdingding.modules.qd.service;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.qdingding.common.service.CrudService;
import com.biostime.qdingding.modules.qd.dao.PrivrecordDao;
import com.biostime.qdingding.modules.qd.entity.Privrecord;
import com.biostime.qdingding.modules.sys.entity.User;

/**
 * 特权纪录Service
 * @author phil
 * @version 2015-12-16
 */
@Service
@Transactional(readOnly = true)
public class PrivrecordService extends CrudService<PrivrecordDao, Privrecord> {

	@Override
		public List<Privrecord> findList(Privrecord entity) {
			if(entity == null){
				entity = new Privrecord();
			}
			
			dataScopeFilter(entity, "dsf", "id=a.center_id", "id=a.create_by");
			
			return super.findList(entity);
		}
	
//  <!-- ————————————————————————————楚河汉界，谁敢动我的，打死! ————————————————————————————————————-->
	
	public int apiInsert(String centerId,String contractId,String privilegeId,String courseorderId){
		Privrecord record = new Privrecord();
		record.setCenterId(Integer.parseInt(centerId));
		record.setPrivilegeId(Integer.parseInt(privilegeId));
		record.setContractId(Integer.parseInt(contractId));
		record.setCreateBy(new User("0"));
		record.setCount(1);
		record.setCourseorderId(Integer.parseInt(courseorderId));
		record.setCreateDate(new Date());
		record.setUpdateBy(new User("0"));
		record.setUpdateDate(new Date()); 
		record.setDelFlag("0"); 
		return dao.apiInsert(record);
	}
	
	public int apiGetLeaveCount(String studentId){
		return dao.apiGetLeaveCount(studentId);
	}
}
